package forJava;

/**
 * 静态代理
 */
public class StaticProxyTest {

    public static void main(String[] args) {

        SendMessage sendMessage = new SendMessageImpl();
        // 向上转型
        SendMessageProxy sendMessageProxy = new SendMessageProxy(sendMessage);
        sendMessageProxy.send("我被增强了...");

    }

}

interface SendMessage {

    void send(String message);

}

class SendMessageImpl implements SendMessage {

    @Override
    public void send(String message) {

        System.out.println("发送消息:" + message);
    }

}

class SendMessageProxy implements SendMessage {

    private final SendMessage sendMessage;

    SendMessageProxy(SendMessage sendMessage) {

        this.sendMessage = sendMessage;
    }

    @Override
    public void send(String message) {

        System.out.println("send方法的前置增强...");
        sendMessage.send(message);
        System.out.println("send方法的后置增强...");
    }

}
